-
-
Notifications
You must be signed in to change notification settings - Fork 28.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Openplantbook integration #42359
Conversation
375e896
to
287ae2f
Compare
I still don't understand what I can do to fix the codecov/patch issue. |
b4933f3
to
99f8025
Compare
You can check which lines of codes are not hit by tests: |
You need 100% coverage for at least config flow. |
Thanks! Now I have 100% covreage of config_flow, and all 3 tests succeeds locally. |
|
||
from .const import ATTR_ALIAS, ATTR_API, ATTR_HOURS, ATTR_SPECIES, CACHE_TIME, DOMAIN | ||
|
||
CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is configured via config_flow, the CONFIG_SCHEMA shouldn't be needed.
species, | ||
) | ||
wait = 0 | ||
while "pid" not in hass.data[DOMAIN][ATTR_SPECIES][species]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
asyncio.Event would be a good replacement for this retry loop.
_LOGGER.debug("Unable to connect to OpenPlantbook: %s", ex) | ||
raise | ||
|
||
return {"title": "Openplantbook API"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: There are three different capitalizations of OpenPlantBook in this file. Should they all be replaced with one, correct branding?
return self.async_create_entry(title=info["title"], data=user_input) | ||
except Exception as ex: | ||
_LOGGER.error("Unable to connect to OpenPlantbook: %s", ex) | ||
raise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An exception while validating input/trying to connect would typically be given back to the user by showing the form again with the the errors field set. This lets the user fix their input and try again. I'm not sure what the user experience of a thrown exception during config flow would be.
@@ -0,0 +1,13 @@ | |||
search: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clear_cache service isn't listed here
|
||
async def test_form(hass): | ||
"""Test we get the form.""" | ||
await setup.async_setup_component(hass, "persistent_notification", {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The component doesn't interact with persistent_notification. Does it need to be initialized in the tests?
entity_id = async_generate_entity_id( | ||
f"{DOMAIN}" + ".{}", plant_data["pid"], current_ids={} | ||
) | ||
hass.states.async_set(entity_id, plant_data["display_pid"], attrs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with anything in the plant area so take this comment with a grain of salt, but it feels unusual that services are creating and destroying entities. In the light/switch/sensor/etc world it'd be more traditional for the config_entry to know about what entities will be created and for them all to be created during setup.
hass.data[DOMAIN] = {} | ||
if ATTR_API not in hass.data[DOMAIN]: | ||
hass.data[DOMAIN][ATTR_API] = OpenPlantBookApi( | ||
entry.data.get("client_id"), entry.data.get("secret") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throughout the component there are magic strings that are used in multiple places. It is very common in HA for these all to be defined as constants so there is less chance for mismatching typos. There are already a bunch of these in const.py but there are many that are not.
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR has been running stale since 5 Jan, without a response. I think it is fair to say this is really stale and should be closed.
Looking at the PR: It doesn't provide any entities, yet it directly injects/modifies data in the state engine by injecting "fake" entities and data. This is absolutely a no-go.
This contribution doesn't fit the Home Assistant model. We represent states, not encyclopedia data. |
I agree that information from openplantbook should not become part of the state of the entities, but there is a lot of value in configuring the plant entity with information from openplantbook. Currently the plant entity yaml exposes all these parameters retrieved from openplantbook as yaml configuration parameters, doesn't it make sense to fill those in automatically? This PR might not have been the best approach, but doesn't the use case make sense ? |
A config flow step could fetch this information when configuring a plant. |
We tried that approach first, however we needed to add a few more data points to the plant object, and that was rejected since you do not allow "config" in the attributes of an entity. |
Proposed change
This PR adds access to the OpenPlantbook API, and is mostly a preparation for a later PR to the Plant component.
The Openplantbook component itself does not do much, except providing a way for Home Assistant to communicate with the OpenPlantbook API and online DB to fetch data.
There are two service calls which allows you to search for plant species, and get data for a specific species.
https://open.plantbook.io/
This PR is a replacement for PR#42200 where the git history was problematic after a bad rebase.
Type of change
Additional information
The component requires the user to get a client id and secret to the OpenPlantbook API. It is configured using a config flow.
The Openplantbook API is the exposed to HA as a class where other components (e.g. the Plant component) can fetch data.
A PR for the Plant component where it can take advantage of the OpenPlantbook API will be submitted once this component is accepted.
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: